# @shuaige : 陈世玉
# @name :top250.py
# @time :2025/1/21 21:08
import json
import re

import data
import requests
import os
data = json.dumps(data)
pattern = re.compile('"(https://aweme.snssdk.com/aweme/v1/play/.*?)"')
result = pattern.findall(data)
result = [i.split("&ratio")[0] for i in result]
result2 = [i.replace("/play/", "/playwm/") for i in result]

for i in result:
    print(i)
headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36',
}
if not os.path.exists("无水印"):
    os.mkdir("无水印")
if not os.path.exists("水印"):
    os.mkdir("水印")

count = 0
for res1 in result:
    count += 1
    videoBin = requests.get(res1, timeout=5, headers=headers)
    with open(f'无水印/{count}.mp4', 'wb') as fb:
        fb.write(videoBin.content)
count = 0
for res2 in result2:
    count += 1
    videoBin = requests.get(res2, timeout=5, headers=headers)
    with open(f'水印/{count}.mp4', 'wb') as fb:
        fb.write(videoBin.content)